package dlg.code.composite.model.aggregates;

import dlg.code.composite.model.TreeNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class DecisionTree {
    private TreeNode root;

    public void genTree(List<TreeNode> nodeList) {
        nodeList.forEach(e -> {
            if (e.getParentId() == null) {
                root = e;
            }
            nodeList.forEach(n -> {
                if (Objects.equals(n.getParentId(), e.getId())) {
                    if (e.getChildList() == null) {
                        e.setChildList(new ArrayList<>());
                    }
                    e.getChildList().add(n);
                }
            });
        });
    }

    public TreeNode getRoot() {
        return root;
    }
}
